package priv.pront.code.mati.province;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class MC0204 {

    static int n, ans = 0;
    static int[] a;
    static Map<Integer, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        int left = 0, right = 1;
        map.put(a[left], 0);
        while (right < n) {
            if (map.containsKey(a[right])) {
                int idx = map.get(a[right]);
                for (int i = left; i <= idx; i++) {
                    map.remove(a[i]);
                }
                left = idx + 1;
            }
            map.put(a[right], right);
            ans = Math.max(ans, right - left + 1);
            right++;

        }
        System.out.println(ans);
    }
}
